﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FlanProject.Combats.Actions
{
    public class IdleCombatAction : CombatAction
    {
        #region State

        public override bool IsOffensive { get { return false; } }
        public override bool IsTargetNeeded { get { return false; } }

        #endregion

        #region Executing Data

        private float idleTime;

        #endregion

        public IdleCombatAction(CombatCharacter character)
            : base(character)
        {

        }

        #region Combat Stage

        protected override void StartStage()
        {
            switch (Stage)
            {
                case CombatActionStage.Preparing:
                {
                    // Idle time in seconds
                    idleTime = (new Random()).Next(2, 4);
                    break;
                }

                case CombatActionStage.Executing:
                {
                    Character.CurrentState = CombatCharacter.States.Idle;
                    break;
                }
            }
        }

        protected override void UpdateCurrentStage(GameTime gameTime)
        {
            if (Stage == CombatActionStage.Executing)
                idleTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        protected override bool IsReadyForNextStage
        {
            get
            {
                switch (Stage)
                {
                    case CombatActionStage.Preparing:
                        return true;

                    case CombatActionStage.Advancing:
                        return true;

                    case CombatActionStage.Executing:
                        return idleTime <= 0;

                    case CombatActionStage.Returning:
                        return true;

                    case CombatActionStage.Finishing:
                        return true;
                }

                return base.IsReadyForNextStage;
            }
        }

        #endregion
    }
}